package xyz.gpgl.config.security;

import common.util.base.CommonUtil;
import common.util.base.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author liubo
 * @created 2019-11-01 14:17
 */
@Slf4j
public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler {

    private  String indexUrl;

    public MyAuthenticationSuccessHandler(String indexUrl){
        super();
        this.indexUrl = indexUrl;
    }

    @Override
    public void onAuthenticationSuccess(HttpServletRequest arg0, HttpServletResponse response, Authentication arg2)
            throws IOException {
        log.info("登录成功");
        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().write(CommonUtil.convertObjectToJson(Result.success(indexUrl)));
    }

}
